/*
 *  libKara - Library for basic instant messaging functions
 *  Copyright (C) 2007 Markus Karnik
 *
 *  This program is free software; you can redistribute it and/or modify it 
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 3 of the License, 
 *  or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 *  for more details.
 *
 *  You should have received a copy of the GNU General Public License along 
 *  with this program; if not, see <http://www.gnu.org/licenses/>.
 *  
 */

package de.karnik.libkara.pluginspecs;

import java.util.HashMap;
import java.util.Vector;

/**
 * The protocol settings class to store all settings.
 * 
 * @author Markus Karnik - markus.karnik@my-design.org
 * @version 1.0
 * @since 1.0
 */
public abstract class ProtocolSettings {

	/**
	 * The predefined hostname value.
	 */
	public static final String STRING_VALUE_HOSTNAME 	= "hostname";
	/**
	 * The predefined password value.
	 */
	public static final String STRING_VALUE_PASSWORD 	= "password";
	/**
	 * The predefined user id value.
	 */
	public static final String STRING_VALUE_USERID 		= "userid";
	
	/**
	 * The predefined port value.
	 */
	public static final String INTEGER_VALUE_PORT 		= "port";
	/**
	 * The predefined status value.
	 */
	public static final String INTEGER_VALUE_STATUS 	= "status";
	
	/**
	 * The predefined logged in value.
	 */
	public static final String BOOLEAN_VALUE_LOGGED_IN 	= "isloggedin";
	
	/**
	 * The string data storage.
	 */
	private HashMap<String,String> stringData = new HashMap<String,String>();
	/**
	 * The integer data storage.
	 */
	private HashMap<String,Integer> intData = new HashMap<String,Integer>();
	/**
	 * The boolean data storage.
	 */
	private HashMap<String,Boolean> booleanData = new HashMap<String,Boolean>();
	
	/**
	 * The required string values key storage.
	 */
	private Vector<String> requiredStringValues = new Vector<String>();
	/**
	 * The required integer values key storage.
	 */
	private Vector<String> requiredIntegerValues = new Vector<String>();
	/**
	 * The required boolean values key storage.
	 */
	private Vector<String> requiredBooleanValues = new Vector<String>();
	
	/**
	 * Returns the complete user id.
	 * 
	 * @return The complete user id.
	 */
	public abstract String getCompleteUserID();
	/**
	 * Constructs a settings object with the default settings.
	 */
	public ProtocolSettings() {
		this.addRequiredStringValue( STRING_VALUE_USERID );
		this.addRequiredStringValue( STRING_VALUE_PASSWORD );
		this.addRequiredStringValue( STRING_VALUE_HOSTNAME );
		
		this.addRequiredIntegerValue( INTEGER_VALUE_PORT );
		this.addRequiredIntegerValue( INTEGER_VALUE_STATUS );
	}
	/**
	 * Adds a required string value key.
	 * 
	 * @param key The key to add.
	 */
	protected void addRequiredStringValue( String key ) {
		this.requiredStringValues.add( key );
	}
	/**
	 * Adds a required integer value key.
	 * 
	 * @param key The key to add.
	 */
	protected void addRequiredIntegerValue( String key ) {
		this.requiredIntegerValues.add( key );
	}
	/**
	 * Adds a required boolean value key.
	 * 
	 * @param key The key to add.
	 */
	protected void addRequiredBooleanValue( String key ) {
		this.requiredBooleanValues.add( key );
	}
	/**
	 *  Returns the required string value keys.
	 * 
	 * @return The keys.
	 */
	public String[] getRequiredStringValues() {
		return this.requiredStringValues.toArray( new String[ this.requiredStringValues.size() ] );
	}
	/**
	 *  Returns the required integer value keys.
	 * 
	 * @return The keys.
	 */	
	public String[] getRequiredIntegerValues() {
		return this.requiredIntegerValues.toArray( new String[ this.requiredIntegerValues.size() ] );
	}
	/**
	 *  Returns the required boolean value keys.
	 * 
	 * @return The keys.
	 */	
	public String[] getRequiredBooleanValues() {
		return this.requiredBooleanValues.toArray( new String[ this.requiredBooleanValues.size() ] );
	}
	/**
	 * Add string data with the specified key to the string storage.
	 * 
	 * @param key The value key.
	 * @param value The value.
	 */
	public void putStringData( String key, String value ) {
		this.stringData.put( key, value );
	}
	/**
	 * Returns the string data of the given key.
	 * 
	 * @param key The data key.
	 * @return The data.
	 */
	public String getStringData( String key ) {
		return this.stringData.get( key );
	}
	/**
	 * Add integer data with the specified key to the integer storage.
	 * 
	 * @param key The value key.
	 * @param value The value.
	 */	
	public void putIntegerData( String key, int value ) {
		this.intData.put( key, Integer.valueOf( value ) );
	}
	/**
	 * Returns the integer data of the given key.
	 * 
	 * @param key The data key.
	 * @return The data.
	 */
	public int getIntegerData( String key ) {
		if( this.intData.get( key ) == null )
			return 0;
		
		return this.intData.get( key ).intValue();
	}
	/**
	 * Add boolean data with the specified key to the boolean storage.
	 * 
	 * @param key The value key.
	 * @param value The value.
	 */
	public void putBooleanData( String key, boolean value ) {
		this.booleanData.put( key, Boolean.valueOf( value ) );
	}
	/**
	 * Returns the boolean data of the given key.
	 * 
	 * @param key The data key.
	 * @return The data.
	 */
	public boolean getBooleanData( String key ) {
		if( this.booleanData.get( key ) == null )
			return false;
		
		return this.booleanData.get( key ).booleanValue();
	}
}
